// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import Layout from './components/Layout.vue'
import router from './router'
import axios from 'axios'
// import VueLazyload from 'vue-lazyload'
import global_ from './components/global.vue'
// import echarts from 'echarts'
import store from './store/store'
import { log } from './tools/log'
import message from './common/message'
// import Layout from './components/jndpc/TypeMessageTop.vue'


Vue.use(ElementUI)
// Vue.use(VueLazyload)
Vue.prototype.GLOBAL = global_
axios.defaults.baseURL = global_.BASE_URL;
Vue.prototype.axios = axios
Vue.prototype.log = log
Vue.prototype.$toast = message.toast
// Vue.prototype.WsData = global_.WsData;
// Vue.prototype.$echarts = echarts 


Vue.config.productionTip = false

function WsDataFun() {
  if ("WebSocket" in window) {
    function randomString(len) {
      len = len || 32;
      var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
      var maxPos = $chars.length;
      var pwd = '';
      for (var i = 0; i < len; i++) {
        pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
      }
      return pwd;
    }
    // var ws = new WebSocket('ws://149.28.155.180:1234');
    // var ws = new WebSocket('ws://47.91.159.30:1234');//测试服
    var ws = new WebSocket('ws://47.96.115.178:1234');//线上地址
    ws.onopen = function () {
      var uid = randomString(32);
      ws.send(uid);
    };
    ws.onmessage = function (e) {
      if (e.data.length !== 32) {
        let wsData = JSON.parse(e.data);
        if (wsData.type == 0) { // 倒计时及首页彩票大厅数据
          store.state.TypeMessage = wsData.data;
          store.state.Table = wsData.table;
          // console.log('store.state.Table>>>', store.state.Table);
          // console.log('store.state.TypeMessage>>>', store.state.TypeMessage);
        } else if (wsData.type == 1) { //预测
          store.state.Forecast = wsData;
          // store.commit('Forecast', wsData)
          // console.log('store.state.Forecast>>>>>', store.state.Forecast);
        }
      }
    };
  } else {
    // 浏览器不支持 WebSocket
    console.log('您的浏览器不支持 WebSocket!');
  }
}
WsDataFun();

function getlotteryType() {
  let str = window.location.href;
  if (str.indexOf('helpCenter') != -1) {
    return;
  } else {
    var index = str.indexOf("#");
    num = str.substring(index);
    let num = num.replace(/[^0-9]/ig, "");
    if (!num) {
      return;
    } else {
      axios.get(`http://47.75.205.251:11111/index/index/getLotteryIdentificationById?lottery_id=${num}`).then(res => {
        store.state.lotteryType = res.data.data[0];
      })
      //本地
      // axios.get(`http://127.0.0.1:11111/index/index/getLotteryIdentificationById?lottery_id=${num}`).then(res => {
      //   store.state.lotteryType = res.data.data[0];
      // })
      // 测试服
      // axios.get(`http://47.91.159.30:10086/index/index/getLotteryIdentificationById?lottery_id=${num}`).then(res=>{
      //   store.state.lotteryType = res.data.data[0];
      // })
    }
  }

}
getlotteryType();


/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: { Layout },
  template: '<Layout/>',
})